<%--
  Created by IntelliJ IDEA.
  User: lixiaodong
  Date: 2018/4/3
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="role_index_div" class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center'" style="">
        <table id="role_index_dg_role" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'east'" style="width: 600px;">
        <table id="role_index_dg_menu" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="role_index_toolbar_role">
    <a id="role_index_add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">添加角色</a>|
    <a id="role_index_update" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改角色</a>|
    <a id="role_index_delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">删除角色</a>
    <a id="role_index_menu" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">设置权限</a>
    <a id="role_index_user" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">添加用户</a>
</div>
<div id="role_index_toolbar_menu">
    <a id="role_index_delete_menu" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true">解除权限</a>
</div>

<script type="text/javascript">
    var _role_index_js = {
        menu_init : function (_queryParams) {
            var _columns = [[
                {field:'id',title:'ID',width:0,hidden:'true'},
                {field:'name',title:'权限名称',width:100},
                {field:'number',title:'权限编号',width:100},
                {field:'value',title:'权限值',width:100},
                {field:'introduce',title:'权限说明',width:300},
                {field:'state',title:'状态',width:100},
            ]];
            var _url = bs.base_url + 'role/getMenus.action';
            bs.datagrid_load('role_index_dg_menu',_columns,_url,'role_index_toolbar_menu',_queryParams);
            $('#role_index_dg_menu').datagrid({pagination:false});
        },
        datagrid_init : function (_queryParams) {
            var _columns = [[
                {field:'id',title:'ID',width:0,hidden:'true'},
                {field:'name',title:'角色名称',width:100},
                {field:'number',title:'角色编号',width:100},
                {field:'introduce',title:'角色说明',width:300},
                {field:'state',title:'状态',width:100},
            ]];
            var _url = bs.base_url + 'role/getByPage.action';
            bs.datagrid_load('role_index_dg_role',_columns,_url,'role_index_toolbar_role',_queryParams);
            $('#role_index_dg_role').datagrid({
                onClickRow:function (index, row) {
                    _role_index_js.menu_init({id:row.id})
                }
            });
        },
        btn_init : function () {
            $('#role_index_add').on('click', function () {
                bs.show_dialog_min('role_dialog',bs.base_url+'role/addUI.action','添加角色',{flag:'add'});
            });
            $('#role_index_update').on('click', function () {
                var _row = $('#role_index_dg_role').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url+'role/addUI.action';
                    var _queryParams = {row:_row, flag:'update'};
                    bs.show_dialog_min('role_dialog',_url,'修改角色信息',_queryParams);
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#role_index_delete').on('click', function () {
                var _row = $('#role_index_dg_role').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url + 'role/delete.action?id='+_row.id;
                    bs.base_ajax_datagrid(_url,'role_index_dg_role','您确认想要删除这个角色信息吗？');
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#role_index_menu').on('click', function () {
                var _row = $('#role_index_dg_role').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url+'role/menuUI.action';
                    var _queryParams = {row:_row};
                    bs.show_dialog_max('role_dialog',_url,'修改角色权限',_queryParams);
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#role_index_user').on('click', function () {
                var _row = $('#role_index_dg_role').datagrid('getSelected');
                if (_row != null){
                    var _url = bs.base_url+'role/userUI.action';
                    var _queryParams = {row:_row};
                    bs.show_dialog_max('role_dialog',_url,'添加用户到该角色',_queryParams);
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
            $('#role_index_delete_menu').on('click', function () {
                var _row0 = $('#role_index_dg_role').datagrid('getSelected');
                var _row1 = $('#role_index_dg_menu').datagrid('getSelected');
                if (_row0 != null && _row1 != null){
                    var _url = bs.base_url + 'role/deleteMenus.action?id='+_row0.id + '&menuId=' + _row1.id;
                    bs.base_ajax_datagrid(_url,'role_index_dg_menu','您确认想要解除这个权限吗？');
                }else {
                    $.messager.alert('警告','请选择一条数据');
                }
            });
        }
    }

    var role_index_app = (function () {
        $(function () {
            _role_index_js.datagrid_init(null);
            _role_index_js.btn_init();
        });
    })();
</script>